package com.example.k12.bean;

import com.example.k12.utlis.AppConfig;
import com.google.gson.annotations.SerializedName;

import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Generated;

import java.util.Objects;

@Entity
public class StudentInfo {
    private double balance;
    private String classesId;
    private String classesName;
    private int collectStatus;
    private String contractId;
    private long createTime;
    private String createUserId;
    private String createUserName;
    private int gender;
    private String gradeId;
    private String gradeName;
    private String idCard;
    private int isDel;
    private String mchId;
    private long modifyTime;
    private String modifyUserId;
    private String name;
    private String parentName;
    private String parentPhone;
    private String picImage;
    private String schoolId;
    private String schoolName;
    private int status;
    @Id
    @SerializedName(value = "uuid", alternate = {"studentId"})
    private String uuid;
    private String wxFaceUserId;
    private String wxUserStatus;
    private int isDayLimitNum; // 是否开启每日限制次数（开启：1；不开启：0）
    private int dayLimitNum; // 每日限制次数
    private int isEveryTimeLimitAmount; // 是否开启单次限额（开启：1；不开启：0）
    private double everyTimeLimitAmount; // 单次限额
    private double consumeAmount = 0.00;// 限制余额
    private int consumeCount = 0;// 消费次数



    @Generated(hash = 1527912200)
    public StudentInfo(double balance, String classesId, String classesName, int collectStatus, String contractId, long createTime,
            String createUserId, String createUserName, int gender, String gradeId, String gradeName, String idCard, int isDel, String mchId,
            long modifyTime, String modifyUserId, String name, String parentName, String parentPhone, String picImage, String schoolId,
            String schoolName, int status, String uuid, String wxFaceUserId, String wxUserStatus, int isDayLimitNum, int dayLimitNum,
            int isEveryTimeLimitAmount, double everyTimeLimitAmount, double consumeAmount, int consumeCount) {
        this.balance = balance;
        this.classesId = classesId;
        this.classesName = classesName;
        this.collectStatus = collectStatus;
        this.contractId = contractId;
        this.createTime = createTime;
        this.createUserId = createUserId;
        this.createUserName = createUserName;
        this.gender = gender;
        this.gradeId = gradeId;
        this.gradeName = gradeName;
        this.idCard = idCard;
        this.isDel = isDel;
        this.mchId = mchId;
        this.modifyTime = modifyTime;
        this.modifyUserId = modifyUserId;
        this.name = name;
        this.parentName = parentName;
        this.parentPhone = parentPhone;
        this.picImage = picImage;
        this.schoolId = schoolId;
        this.schoolName = schoolName;
        this.status = status;
        this.uuid = uuid;
        this.wxFaceUserId = wxFaceUserId;
        this.wxUserStatus = wxUserStatus;
        this.isDayLimitNum = isDayLimitNum;
        this.dayLimitNum = dayLimitNum;
        this.isEveryTimeLimitAmount = isEveryTimeLimitAmount;
        this.everyTimeLimitAmount = everyTimeLimitAmount;
        this.consumeAmount = consumeAmount;
        this.consumeCount = consumeCount;
    }

    @Generated(hash = 2016856731)
    public StudentInfo() {
    }



    // Getters and Setters
    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        this.balance = balance;
    }

    public String getClassesId() {
        return classesId;
    }

    public void setClassesId(String classesId) {
        this.classesId = classesId;
    }

    public String getClassesName() {
        return classesName;
    }

    public void setClassesName(String classesName) {
        this.classesName = classesName;
    }

    public int getCollectStatus() {
        return collectStatus;
    }

    public void setCollectStatus(int collectStatus) {
        this.collectStatus = collectStatus;
    }

    public String getContractId() {
        return contractId;
    }

    public void setContractId(String contractId) {
        this.contractId = contractId;
    }

    public long getCreateTime() {
        return createTime;
    }

    public void setCreateTime(long createTime) {
        this.createTime = createTime;
    }

    public String getCreateUserId() {
        return createUserId;
    }

    public void setCreateUserId(String createUserId) {
        this.createUserId = createUserId;
    }

    public String getCreateUserName() {
        return createUserName;
    }

    public void setCreateUserName(String createUserName) {
        this.createUserName = createUserName;
    }

    public int getGender() {
        return gender;
    }

    public void setGender(int gender) {
        this.gender = gender;
    }

    public String getGradeId() {
        return gradeId;
    }

    public void setGradeId(String gradeId) {
        this.gradeId = gradeId;
    }

    public String getGradeName() {
        return gradeName;
    }

    public void setGradeName(String gradeName) {
        this.gradeName = gradeName;
    }

    public String getIdCard() {
        return idCard;
    }

    public void setIdCard(String idCard) {
        this.idCard = idCard;
    }

    public int getIsDel() {
        return isDel;
    }

    public void setIsDel(int isDel) {
        this.isDel = isDel;
    }

    public String getMchId() {
        return mchId;
    }

    public void setMchId(String mchId) {
        this.mchId = mchId;
    }

    public long getModifyTime() {
        return modifyTime;
    }

    public void setModifyTime(long modifyTime) {
        this.modifyTime = modifyTime;
    }

    public String getModifyUserId() {
        return modifyUserId;
    }

    public void setModifyUserId(String modifyUserId) {
        this.modifyUserId = modifyUserId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getParentName() {
        return parentName;
    }

    public void setParentName(String parentName) {
        this.parentName = parentName;
    }

    public String getParentPhone() {
        return parentPhone;
    }

    public void setParentPhone(String parentPhone) {
        this.parentPhone = parentPhone;
    }

    public String getPicImage() {
        return picImage;
    }

    public void setPicImage(String picImage) {
        this.picImage = picImage;
    }

    public String getSchoolId() {
        return schoolId;
    }

    public void setSchoolId(String schoolId) {
        this.schoolId = schoolId;
    }

    public String getSchoolName() {
        return schoolName;
    }

    public void setSchoolName(String schoolName) {
        this.schoolName = schoolName;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getUuid() {
        return uuid;
    }

    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    public String getWxFaceUserId() {
        return wxFaceUserId;
    }

    public void setWxFaceUserId(String wxFaceUserId) {
        this.wxFaceUserId = wxFaceUserId;
    }

    public String getWxUserStatus() {
        return wxUserStatus;
    }

    public void setWxUserStatus(String wxUserStatus) {
        this.wxUserStatus = wxUserStatus;
    }

    public int getIsDayLimitNum() {
        return isDayLimitNum;
    }

    public void setIsDayLimitNum(int isDayLimitNum) {
        this.isDayLimitNum = isDayLimitNum;
    }

    public int getDayLimitNum() {
        return dayLimitNum;
    }

    public void setDayLimitNum(int dayLimitNum) {
        this.dayLimitNum = dayLimitNum;
    }

    public int getIsEveryTimeLimitAmount() {
        return isEveryTimeLimitAmount;
    }

    public void setIsEveryTimeLimitAmount(int isEveryTimeLimitAmount) {
        this.isEveryTimeLimitAmount = isEveryTimeLimitAmount;
    }

    public double getEveryTimeLimitAmount() {
        return everyTimeLimitAmount;
    }

    public void setEveryTimeLimitAmount(double everyTimeLimitAmount) {
        this.everyTimeLimitAmount = everyTimeLimitAmount;
    }

    public double getConsumeAmount() {
        return this.consumeAmount;
    }

    public void setConsumeAmount(double consumeAmount) {
        this.consumeAmount = consumeAmount;
    }

    public int getConsumeCount() {
        return this.consumeCount;
    }

    public void setConsumeCount(int consumeCount) {
        this.consumeCount = consumeCount;
    }

    /**
     * 校验今日是否还可以消费
     * @param amount 消费金额
     * @return 校验结果，true表示可以消费，false表示不能消费
     */
    public String canConsumeToday(double amount) {
        // 1. 余额要大于付款金额
        if (Objects.requireNonNull(AppConfig.Companion.getInstance().getDeviceInfo()).getPaymentMode() != 2 && this.balance < amount) {
            return "当前余额不足";
        }

        // 2. 如果开启了每日限制次数，当剩余次数不够的时候不能再消费
        if (this.isDayLimitNum == 1) { // 开启了每日限制次数
            if (this.consumeCount >= this.dayLimitNum) { // 剩余次数不足
                return "今日剩余消费次数不足";
            }
        }

        // 3. 如果开启了单次限额的时候，消费金额超过了也不能消费
        if (this.isEveryTimeLimitAmount == 1) { // 开启了单次限额
            if (amount > this.everyTimeLimitAmount) { // 消费金额超过单次限额
                return "本次消费金额超过单次限额";
            }
        }

        // 所有条件都满足，可以消费
        return "";
    }

}
